package com.shop.loan.model.vo;

import cn.hutool.core.date.DateUtil;
import com.shop.loan.model.entity.LoanOrderByMybatis;
import com.shop.loan.model.entity.UserByMybatis;
import com.shop.loan.util.Util;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

@Data
public class ContractCodeVo {

    private Long loanOrderId;
    private String platformName;


    //资管公司
    private String assetCompanyName;
    private String assetCompanyBankAccount;

    private String assetCompanyBankNumber;
    private String assetCompanyBankName;

    /**
     * 融资担保公司
     */
    private String rdCompanyName;
    private String rdCompanyAddress;
    private String rdCompanyLegalName;
    private String rdCompanyPhone;

    /**
     * 小贷公司
     */
    private String loanCompanyName;
    private String loanCompanyAddress;
    private String loanCompanyLegalName;
    private String loanCompanyPhone;


    private String userName;

    private String userPhone;

    private String userIdentity;

    private String userAddress;


    private BigDecimal money;

    private String moneyBig;

    private BigDecimal unPayMoney;

    private BigDecimal payMoney;

    private Integer loanDay;
    private BigDecimal loanRate;

    private Integer period;
    //每期金额
    private BigDecimal periodMoney;
    //担保费
    private BigDecimal shopMoney;
    private String guaranteeBig;

    private String reason;

    private String periodDay_1;
    private BigDecimal periodGuarantee_1;
    private String periodDay_2;
    private BigDecimal periodGuarantee_2;

    //yyyy-mm-dd
    private String signDay;
    //yyyy年mm月dd日
    private String signDayByY;

    private Integer year;

    private String month;

    private String day;

    private String bankName;
    private String bankNumber;

    public ContractCodeVo() {
    }

    public ContractCodeVo(LoanOrderByMybatis loanOrder, UserByMybatis userByMybatis) {
        this.loanOrderId = loanOrder.getId();
        this.money = loanOrder.getMoney();
//        this.guarantee = loanOrder.getShopMoney();
        this.moneyBig = Util.getBigMoney(loanOrder.getMoney());
//        this.guaranteeBig = Util.getBigMoney(loanOrder.getShopMoney());
        this.payMoney = loanOrder.getPayMoney() == null ? BigDecimal.ZERO : loanOrder.getPayMoney();
        this.loanRate = loanOrder.getYearRate();
        this.loanDay = loanOrder.getPeriodDay() * loanOrder.getPeriod();
        this.period = loanOrder.getPeriod();

        int month = DateUtil.thisMonth() + 1;
        int day = DateUtil.thisDayOfMonth();
        if (loanOrder.getLoanTime() != null) {
            this.signDay = DateUtil.formatDate(loanOrder.getLoanTime());
            this.year = DateUtil.year(loanOrder.getLoanTime());

            month = DateUtil.month(loanOrder.getLoanTime()) + 1;
            day = DateUtil.dayOfMonth(loanOrder.getLoanTime());

            this.signDayByY = DateUtil.formatChineseDate(loanOrder.getLoanTime(), false, false);
        } else {
            this.signDay = DateUtil.today();
            this.year = DateUtil.thisYear();

            this.signDayByY = DateUtil.formatChineseDate(new Date(), false, false);
        }
        if (month < 10) {
            this.month = "0" + month;
        } else {
            this.month = "" + month;
        }
        if (day < 10) {
            this.day = "0" + day;
        } else {
            this.day = "" + day;
        }

        if (userByMybatis != null) {
            this.userPhone = userByMybatis.getMobile();
            this.userName = userByMybatis.getCardName();
            this.userIdentity = userByMybatis.getCardNum();
            this.userAddress = userByMybatis.getCardAddress();
        }
    }
}
